/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fbv.tcc.gui;

import fbv.tcc.utils.PropertiesGenerator;
import java.awt.JobAttributes;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

/**
 *
 * @author Victor
 */
public class Configurador extends javax.swing.JFrame {

    /**
     * Creates new form Configurador
     */
    public Configurador() {
        initComponents();

        Properties res = null;
        try {

            res = PropertiesGenerator.carregarProperties();

            txtCaminhoPlanilha.setText(res.getProperty("caminho"));
            txtColunaData.setText(res.getProperty("colunaData"));
            txtColunaRadiacao.setText(res.getProperty("colunaRadiacao"));
            txtCaminhoGrafico.setText(res.getProperty("caminhoGrafico"));
            txtDeslocamento.setText(res.getProperty("deslocamento"));
            txtLatitude.setText(res.getProperty("latitude"));
            txtLongitude.setText(res.getProperty("longitude"));
            txtLatitudeOficialLocalidade.setText(res.getProperty("latitudeOficialLocalidade"));

        } catch (FileNotFoundException ex) {
            Logger.getLogger(Configurador.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Configurador.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtColunaData = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtCaminhoPlanilha = new javax.swing.JTextField();
        btnSalvarConfig = new javax.swing.JButton();
        btnFechar = new javax.swing.JButton();
        txtColunaRadiacao = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtCaminhoGrafico = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtLatitude = new javax.swing.JTextField();
        txtLatitudeOficialLocalidade = new javax.swing.JTextField();
        txtLongitude = new javax.swing.JTextField();
        txtDeslocamento = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configurar PIG 2");
        setMinimumSize(new java.awt.Dimension(480, 390));
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setText("Coluna Planilha Data/Hora");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, -1, -1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("Parâmetros do programa");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));
        getContentPane().add(txtColunaData, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 140, 20));

        jLabel2.setText("Caminho da Planilha");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, -1, -1));

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Coluna Planilha Radiação");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 60, -1, -1));
        getContentPane().add(txtCaminhoPlanilha, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, 460, -1));

        btnSalvarConfig.setText("Salvar");
        btnSalvarConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarConfigActionPerformed(evt);
            }
        });
        getContentPane().add(btnSalvarConfig, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 290, 110, 60));

        btnFechar.setText("Fechar");
        btnFechar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFecharActionPerformed(evt);
            }
        });
        getContentPane().add(btnFechar, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 290, 110, 60));
        getContentPane().add(txtColunaRadiacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 80, 140, 20));

        jLabel5.setText("Diretório dos gráficos salvos");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, -1, -1));
        getContentPane().add(txtCaminhoGrafico, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 260, 460, 20));

        jLabel6.setText("Lat. Oficial da Localidade");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 60, -1, -1));

        jLabel7.setText("Deslocamento");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, -1, -1));

        jLabel8.setText("Latitude");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 120, -1, -1));

        jLabel9.setText("Longitude");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 120, -1, -1));
        getContentPane().add(txtLatitude, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 140, 140, 20));
        getContentPane().add(txtLatitudeOficialLocalidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 80, 140, 20));
        getContentPane().add(txtLongitude, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 140, 140, 20));
        getContentPane().add(txtDeslocamento, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 140, 20));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btnFecharActionPerformed

    private void btnSalvarConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarConfigActionPerformed

        try {
            PropertiesGenerator.salvarProperties(
                    txtCaminhoGrafico.getText(),
                    txtCaminhoPlanilha.getText(),
                    txtColunaData.getText(),
                    txtColunaRadiacao.getText(),
                    txtDeslocamento.getText(),
                    txtLatitude.getText(),
                    txtLongitude.getText(),
                    txtLatitudeOficialLocalidade.getText());

            JOptionPane optionPane = new JOptionPane();
            optionPane.setMessage("Configuração salva com sucesso.");

            optionPane.setMessageType(JOptionPane.DEFAULT_OPTION);
            JDialog dialog = optionPane.createDialog("Salvo com sucesso!");

            dialog.setVisible(true);
            this.setVisible(false);

        } catch (FileNotFoundException ex) {
            Logger.getLogger(Configurador.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Configurador.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btnSalvarConfigActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Configurador.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Configurador.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Configurador.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Configurador.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Configurador().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnFechar;
    private javax.swing.JButton btnSalvarConfig;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField txtCaminhoGrafico;
    private javax.swing.JTextField txtCaminhoPlanilha;
    private javax.swing.JTextField txtColunaData;
    private javax.swing.JTextField txtColunaRadiacao;
    private javax.swing.JTextField txtDeslocamento;
    private javax.swing.JTextField txtLatitude;
    private javax.swing.JTextField txtLatitudeOficialLocalidade;
    private javax.swing.JTextField txtLongitude;
    // End of variables declaration//GEN-END:variables
}
